#include <iostream>
using namespace std;

const int N = 1010;

int n;
int a[N][N];
int f[N][N]; // f[i][j] 表示: [1,1] 走到[i,j]的最大权值
int f1[N];

void dp1()
{
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= i; j++)
		{
			f[i][j] = max(f[i - 1][j], f[i - 1][j - 1]) + a[i][j];
		}
	}

	int ret = 0;
	for (int j = 1; j <= n; j++)
	{
		ret = max(ret, f[n][j]);
	}

	cout << ret << endl;
}

// 空间优化
void dp2()
{
	for (int i = 1; i <= n; i++)
	{
		for (int j = i; j >= 1; j--)
		{
			f1[j] = max(f1[j], f1[j - 1]) + a[i][j];
		}
	}

	int ret = 0;
	for (int j = 1; j <= n; j++)
	{
		ret = max(ret, f1[j]);
	}

	cout << ret << endl;
}

int main()
{
	cin >> n;

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= i; j++)
			cin >> a[i][j];

	// dp1();
	dp2();

	return 0;
}